package com.glory.hzlionpda.adapter;

import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.hzlionpda.R;
import com.glory.hzlionpda.bean.CarryBean;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.List;


public class TrackOutCarryListAdapter extends BaseQuickAdapter<CarryBean, BaseViewHolder> {
    private boolean isShow;

    public TrackOutCarryListAdapter(@Nullable List<CarryBean> data) {
        super(R.layout.adapter_track_out_carry_list, data);
    }

    public void setIsShowDry(boolean isShow) {
        this.isShow = isShow;
    }

    @Override
    protected void convert(BaseViewHolder helper, final CarryBean item) {
        helper.setText(R.id.tvCarryId, item.getCARRIDERID());
        helper.setText(R.id.tvLotId, item.getLOTID());
        final FreeUI_ClearEditText etLotId = helper.getView(R.id.etLotId);
        etLotId.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.toString().length() > 0 && !item.getLOTID().equalsIgnoreCase(charSequence.toString())) {
                    FreeApi_ToastUtils.showFreeToast("LOT ID不匹配", mContext, false, Toast.LENGTH_SHORT);
                } else {
                    item.setSelect(true);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        FreeUI_ClearEditText etDryer = helper.getView(R.id.etDryer);
        if (isShow) {
            etDryer.setVisibility(View.VISIBLE);
            etDryer.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    item.setDRYID(charSequence.toString());
                }

                @Override
                public void afterTextChanged(Editable editable) {

                }
            });
        } else {
            etDryer.setVisibility(View.GONE);
        }
    }
}
